Skip to content

πŸ”’ Fix SSRF vulnerability in Fetcher (DNS Rebinding)#40

Closed
saurabhsharma2u wants to merge 2 commits into
mainfrom
fix-ssrf-fetcher-8560312622372837981
Closed

πŸ”’ Fix SSRF vulnerability in Fetcher (DNS Rebinding)#40
saurabhsharma2u wants to merge 2 commits into
mainfrom
fix-ssrf-fetcher-8560312622372837981

Conversation

@saurabhsharma2u

Copy link
Copy Markdown
Contributor

This PR fixes a Server-Side Request Forgery (SSRF) vulnerability caused by a Time-of-Check Time-of-Use (TOCTOU) race condition in the Fetcher class.

🎯 Vulnerability

Previously, Fetcher performed a DNS resolution check (IPGuard.validateHost) before initiating the HTTP request. An attacker could exploit the time window between this check and the actual connection to rebind the DNS record to an internal IP (DNS Rebinding), bypassing the check.

πŸ›‘οΈ Solution

The fix removes the pre-validation for domain names and relies entirely on the secureDispatcher (which uses a custom lookup function) to validate the IP address at the moment of connection establishment. This eliminates the race condition.

  • Explicit IP Literals: Still validated immediately using net.isIP and IPGuard.isInternal to fail fast.
  • Domains: Validated by undici via secureDispatcher.
  • Error Handling: Fetcher now catches EBLOCKED errors thrown by IPGuard and correctly reports them as blocked_internal_ip.

βœ… Verification

  • Added plugins/core/tests/fetcher_dispatcher.test.ts which mocks undici and IPGuard to simulate an internal IP block at connection time, verifying that Fetcher handles it correctly and returns blocked_internal_ip.
  • Verified that existing safety tests pass.

PR created automatically by Jules for task 8560312622372837981 started by @saurabhsharma2u

Replaces the vulnerable TOCTOU domain validation check with a robust
connection-time validation using `secureDispatcher`.

Explicit IP literals are still validated early using `net.isIP` and `IPGuard.isInternal`
to fail fast, but domain names are now resolved and validated atomically
by `undici`'s lookup hook, preventing DNS rebinding attacks.

Fetcher now correctly catches `EBLOCKED` errors from the dispatcher and
returns `blocked_internal_ip` status.

Added `tests/fetcher_dispatcher.test.ts` to verify the fix and integration
with `secureDispatcher` failure modes.
@google-labs-jules

Copy link
Copy Markdown

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Replaces the vulnerable TOCTOU domain validation check with a robust
connection-time validation using `secureDispatcher`.

Explicit IP literals are still validated early using `net.isIP` and `IPGuard.isInternal`
to fail fast, but domain names are now resolved and validated atomically
by `undici`'s lookup hook, preventing DNS rebinding attacks.

Fetcher now correctly catches `EBLOCKED` errors from the dispatcher and
returns `blocked_internal_ip` status.

Added `tests/fetcher_dispatcher.test.ts` to verify the fix and integration
with `secureDispatcher` failure modes.

Also fixed lint warnings in `transport.test.ts` and `crawler.ts`.
@saurabhsharma2u

Copy link
Copy Markdown
Contributor Author

Closing as this was addressed by PR 42 which fixed the SSRF TOCTOU issue exactly the same way without the unnecessary lockfile bumps.

@saurabhsharma2u
saurabhsharma2u deleted the fix-ssrf-fetcher-8560312622372837981 branch February 25, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant